package com.mall.member.controller;

import com.mall.common.utils.Result;
import com.mall.member.entity.MemberEntity;
import com.mall.member.feign.CouponFeignService;
import com.mall.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Objects;


@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @Autowired
    CouponFeignService couponFeignService;

    @GetMapping("/coupons")
    public Result test(){
        MemberEntity memberEntity = new MemberEntity();
        memberEntity.setUsername("张三");

        Result result = couponFeignService.membercoupons();
        return Objects.requireNonNull(Result.ok().put("member", memberEntity)).put("coupons",result.get("coupons"));
    }



    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(){
        return Result.ok().put("page", memberService.list());
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return Result.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result save(@RequestBody MemberEntity member){
		memberService.save(member);

        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
